﻿using System;

namespace AutoCompleteTextBox
{
    public class SettingsObject
    {  
        public int MaxResults { get; set; }

        public int MinQueryLength { get; set; }

        public int QueryDelay { get; set; }

        public MatchVariants ResultHighlighter { get; set; }

        public MatchVariants ResultFilters { get; set; }

        public bool AllowBrowserAutocomplete { get; set; }

        public bool EnableCache { get; set; }

        public string QueryDelimiter { get; set; }

        public string ResultFormatter { get; set; }

        public bool ActivateFirstItem { get; set; }

        public bool AlwaysShowList { get; set; }

        public bool Circular { get; set; }

        public bool ScrollIntoView { get; set; }

        public bool TabSelect { get; set; }

        public string Align { get; set; }

        public string Source { get; set; }

        public string ClientID { get; set; }

        public string ResultListLocator { get; set; }

        public string ResultTextLocator { get; set; }

        public string RequestTemplate { get; set; }

        public string GetString()
        {
            string settingsObject = "\n" + "var " + ClientID.ToString() + " = {"
                            + (MaxResults != DefaultProperties.DefaultMaxResults ? "maxResults: " + MaxResults + "," : "")
                            + (MinQueryLength != DefaultProperties.DefaultMinQueryLength ? "minQueryLength: " + MinQueryLength + "," : "")
                            + (QueryDelay != DefaultProperties.DefaultQueryDelay ? "queryDelay: " + QueryDelay + "," : "")
                            + (AllowBrowserAutocomplete != DefaultProperties.DefaultAllowBrowserAutocomplete ? "allowBrowserAutocomplete: " + Convert.ToString(AllowBrowserAutocomplete).ToLower() + "," : "")
                            + (EnableCache != DefaultProperties.DefaultEnableCache ? "enableCache: " + Convert.ToString(EnableCache).ToLower() + "," : "")
                            + (ActivateFirstItem != DefaultProperties.DefaultActivateFirstItem ? "activateFirstItem: " + Convert.ToString(ActivateFirstItem).ToLower() + "," : "")
                            + (AlwaysShowList != DefaultProperties.DefaultAlwaysShowList ? "alwaysShowList: " + Convert.ToString(AlwaysShowList).ToLower() + "," : "")
                            + (Circular != DefaultProperties.DefaultCircular ? "circular: " + Convert.ToString(Circular).ToLower() + "," : "")
                            + (ScrollIntoView != DefaultProperties.DefaultScrollIntoView ? "scrollIntoView: " + Convert.ToString(ScrollIntoView).ToLower() + "," : "")
                            + (TabSelect != DefaultProperties.DefaultTabSelect ? "tabSelect: " + Convert.ToString(TabSelect).ToLower() + "," : "");

            if (ResultFormatter != null)
                settingsObject += " resultFormatter: " + ResultFormatter + ",";
            if (ResultHighlighter != MatchVariants.None)
                settingsObject += " resultHighlighter: '" + ResultHighlighter.ToString() + "',";
            if (ResultFilters != MatchVariants.None)
                settingsObject += " resultFilters: '" + ResultFilters.ToString() + "',";
            if (QueryDelimiter != null)
                settingsObject += " queryDelimiter: " + QueryDelimiter + ",";
            if (RequestTemplate != null)
                settingsObject += " requestTemplate: '" + RequestTemplate + "',";
            if (ResultListLocator != null)
                settingsObject += " resultListLocator: " + "'" + ResultListLocator + "',";
            if (ResultTextLocator != null)
                settingsObject += " resultTextLocator: " + "'" + ResultTextLocator + "',";
            if (Align != null)
                settingsObject += " align: {" + Align + "},";

            settingsObject += " source: " + Source + "} ";

            return settingsObject;
        }
    }
}
